package com.qf.smartdevice.controller;

import com.github.pagehelper.PageInfo;
import com.qf.smartdevice.dto.R;
import com.qf.smartdevice.dto.UserDto;
import com.qf.smartdevice.pojo.User;
import com.qf.smartdevice.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping("/users")
    public R getAllUsers(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int limit,String username,@RequestParam(defaultValue = "-100") int status){
        PageInfo<User> pageInfo=userService.findAllUserByPage(page, limit,username,status);
        return R.setOK(pageInfo);
    }

    @PostMapping("/user")
    public R addUser(@RequestBody UserDto user){
        userService.addUser(user);
        return  R.setOK(null);
    }

    @DeleteMapping("/users")
    public R deleteByIds(Integer[] ids){
        int result = userService.deleteByIds(ids);
        return R.setOK(null);
    }
    @PutMapping("/user")
    public R updateUser(UserDto userDto){
        userService.updateUser(userDto);
        return R.setOK(null);
    }
}
